//倒计时
import { computed, onUnmounted, ref } from "vue"
import dayjs from "dayjs"
export const timeout = ()=>{
    let timerid=null
    const time = ref(0)
    //格式化时间
    const formtime =computed(()=>{
      return  dayjs.unix(time.value).format('mm分ss秒')
    })
    const start =(currtime)=>{
        time.value=currtime
    timerid =  setInterval(() => {
            time.value--
        }, 1000);
    }
    //组件销毁时清楚定时器
    onUnmounted(()=>{
    if(timerid) clearInterval(timerid)
    })
    return {
        formtime,start
    }
}